﻿using System;
using System.Data.Common;
using CoreEx.Database.Query.Expressions;
using CoreEx.Database.Query.Translators;

namespace CoreEx.Database.Query
{
    ///<summary>
    /// Extends the <see cref="DbProviderFactory"/> with the capability to create <see cref="DbQueryTranslator"/> instances.
    ///</summary>
    public static class DbProviderFactoryExtensions
    {
        /// <summary>
        /// Creates a provider specific <see cref="DbQueryTranslator"/> instance.
        /// </summary>
        /// <param name="dbProviderFactory"></param>
        /// <returns></returns>
        public static DbQueryTranslator CreateQueryTranslator(this DbProviderFactory dbProviderFactory)
        {            
            if (dbProviderFactory.GetType().Name == "SqlClientFactory")
                return new SqlQueryTranslator(dbProviderFactory);
            throw new InvalidOperationException("No DbQueryTranslator found!!");            
        }
    }
}
